#include "RingQueue.hpp"

void *producer(void *args)
{
    RingQueue<int> *rqp = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data = rand() % 10;
        rqp->push(data);
        cout << "Propthread[" << pthread_self() << "]"
             << "生产了一个数据：" << data << endl;
             sleep(1);
    }
}

void *consumer(void *args)
{
    RingQueue<int> *rqp = static_cast<RingQueue<int> *>(args);
    while (true)
    {
        int data = rqp->pop();
        cout << "Conpthread[" << pthread_self() << "]"
             << "消费了一个数据：" << data << endl;
    }
}
int main()
{
    srand((unsigned int)time(nullptr) ^ getpid());
    RingQueue<int> rq;
    pthread_t c1, p1;
    pthread_create(&p1, nullptr, producer, &rq);
    pthread_create(&c1, nullptr, consumer, &rq);
    pthread_join(c1, nullptr);
    pthread_join(p1, nullptr);
    return 0;
}